import os
import uuid
import config
from flask_restful import Resource,request
from werkzeug.datastructures import FileStorage


class UploadApi(Resource):
    def post(self):
        print(request.files)
        upFile:FileStorage = request.files.get('photo')

        # 获取文件名的扩展名
        extName = "." + upFile.filename.split('.')[-1]
        # extName = upFile.filename[-4:]
        fileName = str(uuid.uuid4()) + extName
        saveFilePath = os.path.join(config.STITIC_DIR, fileName )

        upFile.save(saveFilePath, 1024)
        upFile.close()
        return {"msg":"上传文件成功", "path":'/static/'+fileName}